# remove total row so that it's 35 by 8, including column of conceptsq1 <-select(q1, -9)q2 <-select(q2, -9)q3 <-select(q3, -9)q4 <-select(q4, -9)q5 <-select(q5, -9)head(q1, 2)
Code
head(q2, 2)
Code
head(q3, 2)
Code
head(q4, 2)
Code
head(q5, 2)
Code
# Join columns by term column, to create 35 by 35concepts <-left_join(q1,q2,by="...1")concepts <-left_join(concepts,q3,by="...1")concepts <-left_join(concepts,q4,by="...1")concepts <-left_join(concepts,q5,by="...1")concepts <-select(concepts, -1)rownames(concepts)<-colnames(concepts)namesss <-colnames(concepts)
`
Code
concepts <-as.matrix(concepts)#replace NA's with Zero as the value is not missing, there is just no tie so there weight it 0concepts[is.na(concepts)] <-0# Set diag to false to remove self loopscg <-graph_from_adjacency_matrix(concepts)#Save the graph as a data frame that shows each ties and their weight.cg_frame <-get.data.frame(cg)
Create a tnet object out of single counted actor ties, with weights being the count of the tie appearence
Code
# Identify unique verticesunique_vertices <-unique(c(cg_frame$from, cg_frame$to))valid_vertices <- unique_vertices[nchar(unique_vertices) >0]# Create an empty graphcg_graph <-graph(edges =numeric(0), directed =FALSE)# Add vertices to the graphcg_graph <-add_vertices(cg_graph, nv =length(valid_vertices), name = valid_vertices)# Count the occurrences of each unique tieties_count <-table(apply(cg_frame, 1, function(x) paste(sort(x), collapse ="-")))# Extract tie information directlytie_info <-strsplit(names(ties_count), "-")from_vertices <-sapply(tie_info, `[`, 1)to_vertices <-sapply(tie_info, `[`, 2)weights <-as.vector(ties_count)# Create a data framecg_tie_df <-data.frame(from = from_vertices, to = to_vertices, weight = weights)# Print the data framehead(cg_tie_df)
creating tnet and statnet object
Code
cg_tie_df$from <-as.integer(as.factor(cg_tie_df$from))cg_tie_df$to <-as.integer(as.factor(cg_tie_df$to))# Create the network objectcg_tnet <-as.tnet(cg_tie_df, type ="weighted one-mode tnet")cg.ig <-tnet_igraph(cg_tnet, type ="weighted one-mode tnet", directed =NULL)
Node-Level Measures
Code
#Out Degree/ out-strength con.outdegree <-degree_w(cg_tnet, measure =c("degree", "output"), type="out", alpha =1)#In Degree/ In-strength con.indegree <-degree_w(cg_tnet, measure =c("degree", "output"), type="in", alpha =1)#closenessc_close <-closeness_w(cg_tnet, directed =NULL, gconly =FALSE, alpha =1)#betweenessc_btwn <-betweenness_w(cg_tnet, directed =NULL, alpha =1)#constraints#Rename the columns because the function output names the columns the same regardless of the IN;Out statuscolnames(con.outdegree)[2] <-"Out-Strength"colnames(con.outdegree)[3] <-"Out-Degree"colnames(con.indegree)[2] <-"In-Strength"colnames(con.indegree)[3] <-"In-Degree"#Join the node measures to the same data framecon.nodes <-left_join(as.data.frame(con.outdegree), as.data.frame(con.indegree), by="node")con.nodes <-left_join(as.data.frame(con.nodes), as.data.frame(c_close), by="node")con.nodes <-left_join(con.nodes, as.data.frame(c_btwn), by="node")#temporary rename of node column to "name" to join the evigenor centrality for each nodes to the dataset and then "node" was replaced as the variable name for the nodescolnames(con.nodes)[1] <-"name"cg.stat <-as.network.matrix(cg_tnet) set.vertex.attribute(cg.stat, "name",namesss) con.nodes <-left_join(con.nodes, get.eigen(cg.stat), by ="name")colnames(con.nodes)[1] <-"node"laplacian(cg.ig)